package jdbc_code;

import util.jdbcUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class jdbcDemo9 {

    public boolean insert (String username, String password) {
        if (username == null || password == null) {
            return false;
        }

        Connection conn = null;
        PreparedStatement pstmt = null;

        try {
            //1.获取连接
            conn = jdbcUtils.getConnection();
            //2，定义sql
            String sql = "insert into user values (? ,? , ?)";
            //3，获取执行sql对象
            pstmt = conn.prepareStatement(sql);
            //给问号赋值
            pstmt.setString(1,null);
            pstmt.setString(2,username);
            pstmt.setString(3,password);
            //4，执行添加，不需要传递sql
            int i = pstmt.executeUpdate();
            //5.处理结果
            System.out.println(i);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            jdbcUtils.close(pstmt, conn);
        }

        return false;
    }
}
